class BroadcastsController < ApplicationController
  layout "general"
  before_filter :login_required, :only => :create
  verify :only => :create, :method => :post, :redirect_to => {:controller => 'schools', :action => 'homepage'}
  
  def create
    bc = Broadcast.new(params[:broadcast])
    bc.from = self.current_user.id
    bc.site = 1 #fangjia1kg
    bc.save!
    redirect_to home_path
  end
  
  def list
    @broadcasts = Broadcast.find(:all, :conditions => "site=1",
                                       :order => "broadcasts.created_at desc", 
                                       :joins => "left join users on broadcasts.from = users.id",
                                       :select => "broadcasts.content, broadcasts.from, broadcasts.created_at, users.login, users.id")
  end
end
